import copy
from multiprocessing.managers import BarrierProxy

import pytest
import allure

from core.globalContext import G_context
from extend.keyword import Keyword
from parse.YamlCaseParse import yaml_read, load_yaml_files, get_data_from_yaml
from utils.VarRender import Refresh

keyword = Keyword ()
# filepath = r'C:\peipei_study\接口自动化\examples\yaml_testcase\yaml_testcase.yaml'
filepath = r'C:\peipei_study\接口自动化\examples\yaml_testcase'
case_info = load_yaml_files (filepath)
context = get_data_from_yaml (filepath)
print(case_info)

@pytest.mark.parametrize ('case_info', case_info)
def test_login_excute(case_info):
    allure.dynamic.title (case_info['desc'])
    try:
        allure.step ('获取测试名称')
        steps = case_info.get ('steps', None)
        for step in steps:
            step_name = list (step.keys())[0]
            step_value = list (step.values ())[0]
            print (f'开始执行测试步骤{step_name}-------{step_value}')
            dict_123 = G_context ().show_dict ()
            print ("取出字典中的内容", dict_123)
            step_value = eval (Refresh (step_value, G_context ().show_dict ()))
            print ('公共变量step_value=====', step_value)
            try:
                key = step_value['关键字']
                key_function = keyword.__getattribute__ (key)
            except Exception as e:
                print ('3456', e)
            respone = key_function (**step_value)
            print ("+++++++++++++++++000", respone)

    except Exception as e:
        assert False, f'核心处理器调用文件失败{e}'
    finally:
        print ("测试用例执行完成")

